﻿using System;
using System.Collections.Generic;
using System.Linq;
using ZilLion.Service.Core.DapperWrapper;
using ZilLion.Service.Core.DapperWrapper.SqlServer;
using ZilLion.Service.WeChatMall.Domain.Entitys.ShopInfo;
using ZilLion.Service.WeChatMall.Domain.Repositorys.Interface.ShopInfo;

namespace ZilLion.Service.WeChatMall.Domain.Repositorys.ShopInfo
{
    public class ShopGsRelationShipReponsitory : SqlServerRespository<ShopGsRelationShipEntity>,
        IShopGsRelationShipReponsitory
    {
        public ShopGsRelationShipReponsitory()
        {
            Context = new WechatMallContext();
        }

        public IList<ShopGsRelationShipEntity> GetRelationByShopid(long shopid)
        {
            var querysql = DapperHelper.CreateColSqlByMap<ShopGsRelationShipEntity>();
            var sql = $@"select {querysql} from shopgsrelationship where shopid=@shopid";
            var result = GetList(sql, new {shopid});
            return result.ToList();
        }

        public void AddRelationShip(ShopGsRelationShipEntity entity, UnitOfWork unit = null)
        {
            entity.UpdatedTime = DateTime.Now;
            Add(entity, unit);
        }

        public void RemoveRelationShip(ShopGsRelationShipEntity entity, UnitOfWork unit = null)
        {
            entity.UpdatedTime = DateTime.Now;
            Remove(entity, unit);
        }

        public void RemoveByGsid(long gsid, UnitOfWork unit = null)
        {
            DapperHelper.Execute($"delete from shopgsrelationship where gsid=@gsid", Context, unit, new {gsid});
        }


        public void RemoveRelationByShopid(long shopid, UnitOfWork unit = null)
        {
            DapperHelper.Execute("DELETE FROM shopgsrelationship WHERE shopid=@shopid", Context, unit, new {shopid});
        }
    }
}